#include <sensrvchannel.h>
#include <sensrvaccelerometersensor.h> 
#include <sensrvtappingsensor.h> 
#include <sensrvorientationsensor.h> 

#include "SensorDataListener.h"


CSensorDataListener::CSensorDataListener(int transactionID, Sensors &sensors) : m_transactionID(transactionID), m_sensors(sensors)
    {    
    }

CSensorDataListener::~CSensorDataListener()
    {
    // No implementation required
    }

void CSensorDataListener::DataReceived( CSensrvChannel& aChannel,
                                               TInt /*aCount*/,
                                               TInt /*aDataLost*/ )
    {
    TSensrvChannelInfo info = aChannel.GetChannelInfo();

    if( info.iChannelType == KSensrvChannelTypeIdAccelerometerDoubleTappingData )
        {
        TSensrvTappingData tappingData;
        TPckg<TSensrvTappingData> tappingPackage( tappingData );
        aChannel.GetData( tappingPackage );
        m_sensors.tappingEvent(m_transactionID, tappingData.iDirection, tappingData.iTimeStamp.Int64());
        }

    else if( info.iChannelType == KSensrvChannelTypeIdAccelerometerXYZAxisData )
        {
        TSensrvAccelerometerAxisData accData;
        TPckg<TSensrvAccelerometerAxisData> accPackage( accData );
        aChannel.GetData( accPackage );
        m_sensors.accelerometerEvent(m_transactionID, accData.iAxisX, accData.iAxisY, accData.iAxisZ, accData.iTimeStamp.Int64());
        }

    else if( info.iChannelType == KSensrvChannelTypeIdOrientationData )
        {
        TSensrvOrientationData orientationData;
        TPckg<TSensrvOrientationData> accPackage( orientationData );
        aChannel.GetData( accPackage );
        m_sensors.orientationEvent(m_transactionID, orientationData.iDeviceOrientation, orientationData.iTimeStamp.Int64());
        }
    }

void CSensorDataListener::DataError( CSensrvChannel& /*aChannel*/,
                                            TSensrvErrorSeverity /*aError*/ )
    {
    }

void CSensorDataListener::GetDataListenerInterfaceL( 
    TUid /*aInterfaceUid*/, TAny*& aInterface )
    {
    // Set interface as NULL to indicate only default interface currently supported.
    // If new interface(s) is being introduced and application wants to support that
    // aInterfaceUid must be checked and aInterface set accordingly.
    aInterface = NULL;
    }
